<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>场馆列表</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background-color: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            margin-bottom: 20px;
        }
        .btn {
            display: inline-block;
            padding: 8px 15px;
            background-color: #4CAF50;
            color: white;
            text-decoration: none;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            margin-bottom: 20px;
        }
        .btn:hover {
            background-color: #45a049;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        th, td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        th {
            background-color: #f2f2f2;
        }
        tr:hover {
            background-color: #f5f5f5;
        }
        .venue-image {
            width: 100px;
            height: 100px;
            object-fit: cover;
        }
        .action-btn {
            padding: 5px 10px;
            margin-right: 5px;
            text-decoration: none;
            border-radius: 3px;
            color: white;
        }
        .edit-btn {
            background-color: #2196F3;
        }
        .delete-btn {
            background-color: #f44336;
        }
        .status-btn {
            background-color: #FF9800;
        }
        .status-available {
            color: #4CAF50;
        }
        .status-maintenance {
            color: #f44336;
        }
        .nav-right {
            float: right;
        }
        .logout-btn {
            background-color: #dc3545;
            color: white;
            padding: 8px 15px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
        }
        .logout-btn:hover {
            background-color: #c82333;
        }
        .pagination {
            margin-top: 20px;
            text-align: center;
        }
        .pagination a {
            display: inline-block;
            padding: 8px 16px;
            text-decoration: none;
            color: #4CAF50;
            border: 1px solid #ddd;
            margin: 0 4px;
        }
        .pagination a:hover {
            background-color: #f5f5f5;
        }
        .pagination .active {
            background-color: #4CAF50;
            color: white;
            border: 1px solid #4CAF50;
        }
        .pagination .disabled {
            color: #ddd;
            pointer-events: none;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>场馆列表</h1>
            <div class="nav-right">
                <span style="margin-right: 15px;">欢迎，${sessionScope.user.username}</span>
<%--                <a href="${pageContext.request.contextPath}/admin/index" class="btn" style="margin-right: 10px;">返回首页</a>--%>
                <c:if test="${sessionScope.user.role == 'admin'}">
                    <a href="${pageContext.request.contextPath}/admin/index" class="btn" style="margin-right: 10px;">返回首页</a>
                </c:if>
                <a href="${pageContext.request.contextPath}/user/logout" class="logout-btn">退出登录</a>
            </div>
        </div>
<%--        <a href="${pageContext.request.contextPath}/venue/add" class="btn">添加场馆</a>--%>
        <c:if test="${sessionScope.user.role == 'admin'}">
            <a href="${pageContext.request.contextPath}/venue/add" class="btn">添加场馆</a>
        </c:if>
        <c:if test="${sessionScope.user.role == 'student'}">
            <a href="${pageContext.request.contextPath}/reservation/list"
               class="action-btn edit-btn">查看预约记录</a>
        </c:if>
        <table>
            <thead>
                <tr>
                    <th>ID</th>
                    <th>图片</th>
                    <th>名称</th>
                    <th>位置</th>
                    <th>描述</th>
                    <th>容量</th>
                    <th>状态</th>
                    <th>创建时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <c:forEach items="${venues}" var="venue">
                    <tr>
                        <td>${venue.id}</td>
                        <td>
                            <c:if test="${not empty venue.imagePath}">
                                <img src="${venue.imagePath}" 
                                     alt="${venue.name}" class="venue-image">
                            </c:if>
                        </td>
                        <td>${venue.name}</td>
                        <td>${venue.location}</td>
                        <td>${venue.description}</td>
                        <td>${venue.capacity}</td>
                        <td class="status-${venue.status}">
                            ${venue.status == 'available' ? '可用' : '维护中'}
                        </td>
                        <td>
                            <fmt:formatDate value="${venue.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
                        </td>
                        <td>
                            <c:if test="${sessionScope.user.role == 'student'}">
                                <a href="${pageContext.request.contextPath}/reservation/add/${venue.id}"
                                   class="action-btn edit-btn">预约</a>
                            </c:if>

                            <c:if test="${sessionScope.user.role == 'admin'}">
                                <a href="${pageContext.request.contextPath}/venue/edit/${venue.id}"
                                   class="action-btn edit-btn">编辑</a>
                                <a href="${pageContext.request.contextPath}/venue/delete/${venue.id}"
                                   class="action-btn delete-btn"
                                   onclick="return confirm('确定要删除这个场馆吗？')">删除</a>
                                <a href="${pageContext.request.contextPath}/venue/updateStatus/${venue.id}?status=${venue.status == 'available' ? 'maintenance' : 'available'}"
                                   class="action-btn status-btn">
                                        ${venue.status == 'available' ? '设为维护' : '设为可用'}
                                </a>
                            </c:if>
                        </td>
                    </tr>
                </c:forEach>
            </tbody>
        </table>
        
        <div class="pagination">
            <c:if test="${pageParam.pageNum > 1}">
                <a href="${pageContext.request.contextPath}/venue/list?pageNum=1">首页</a>
                <a href="${pageContext.request.contextPath}/venue/list?pageNum=${pageParam.pageNum - 1}">上一页</a>
            </c:if>
            
            <c:forEach begin="1" end="${pageParam.totalPages}" var="i">
                <c:choose>
                    <c:when test="${i == pageParam.pageNum}">
                        <a href="#" class="active">${i}</a>
                    </c:when>
                    <c:otherwise>
                        <a href="${pageContext.request.contextPath}/venue/list?pageNum=${i}">${i}</a>
                    </c:otherwise>
                </c:choose>
            </c:forEach>
            
            <c:if test="${pageParam.pageNum < pageParam.totalPages}">
                <a href="${pageContext.request.contextPath}/venue/list?pageNum=${pageParam.pageNum + 1}">下一页</a>
                <a href="${pageContext.request.contextPath}/venue/list?pageNum=${pageParam.totalPages}">末页</a>
            </c:if>
            
            <span style="margin-left: 20px;">
                共 ${pageParam.total} 条记录，每页 ${pageParam.pageSize} 条
            </span>
        </div>
    </div>
</body>
</html> 